home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / bbsutil / hsrc_117.zip / POSTMESS.C < prev    next >
C/C++ Source or Header  |  1990-11-27  |  16KB  |  559 lines

  1. #include <msgg.h>
  2. #include <twindow.h>
  3. #include <keys.h>
  4. #include "headedit.h"
  5. #include "headid.h"
  6.  
  7. extern word vbase;
  8. extern word maxx;
  9. extern word maxy;
  10. extern char current_color;
  11. extern word videomethod;
  12. extern WINDOW *ewnd;
  13.  
  14. extern long make_msgid (void);
  15.  
  16.  
  17. void pascal post_mess (char *fname) {
  18.  
  19.  char *p;
  20.  char message[133];
  21.  word lenmess;
  22.  struct date dos_date;
  23.  int handlem;
  24.  int handlet;
  25.  int handlef;
  26.  long mlen;
  27.  long tlen;
  28.  long flen;
  29.  struct ffblk f;
  30.  char level=0;
  31.  char temp;
  32.  struct _carbon *carbon[20]={NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
  33.                              NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
  34.  char numcarbons=0;
  35.  WINDOW *carbwnd=NULL;
  36.  struct _bomb_addr *bomb_addr=NULL;
  37.  char lastnumcarbons=0;
  38.  
  39.  
  40. EditSomeMore:
  41.  
  42.  if (!*fname) {
  43.      strcpy(message,"MSGTMP");
  44.  }
  45.  else strcpy(message,fname);
  46.  *filename=0;
  47.  if ((currarea->attr & ANSI) && ansieditor) strcpy(filename,ansieditor);
  48.  else if (editor) strcpy(filename,editor);
  49.  if(*filename) {
  50.     do_spawn(filename);
  51.  }
  52.  else {
  53.     if(template) {
  54.         strcpy(filename,template);
  55.         do_spawn(filename);
  56.     }
  57.     strcpy(notefile,"MSGTMP");
  58.     notepad();
  59.  }
  60.  
  61.  if (findfirst(message,&f,0)) level=1;
  62.  else if (f.ff_fsize<3L) level=1;
  63.  
  64.  if (!level) {
  65. AskAgain:
  66.     set_help ("atpost    ",0,22);
  67.     show_header(0);
  68.     if(carbon) {
  69.  
  70.         int register x;
  71.  
  72.         if(lastnumcarbons!=numcarbons) {
  73.             if(carbwnd)    delete_window(carbwnd);
  74.             if((currarea->attr & NET) || (currarea->attr & ALTERNATE)) {
  75.                 carbwnd=establish_window(1,maxy-24,21,70);
  76.             }
  77.             else carbwnd=establish_window(1,maxy-24,21,40);
  78.             set_border(carbwnd,3);
  79.             set_title(carbwnd," Carbons ");
  80.             set_colors(carbwnd,BORDER,7,0,0);
  81.             display_window(carbwnd);
  82.             wcursor(carbwnd,0,0);
  83.             for(x=0;x<numcarbons;x++) {
  84.                 if((currarea->attr & NET) || (currarea->attr & ALTERNATE)) {
  85.                     wprintf(carbwnd," %-36s (%u:%u/%u.%u) %d\x9b",carbon[x]->name,carbon[x]->zone,carbon[x]->net,carbon[x]->node,carbon[x]->point);
  86.                 }
  87.                 else wprintf(carbwnd," %s",carbon[x]->name);
  88.                 if(x<numcarbons-1)wprintf(carbwnd,"\n");
  89.             }
  90.             lastnumcarbons=numcarbons;
  91.         }
  92.     }
  93.     if (msg.d_zone!=msg.o_zone && ((currarea->attr & NET) || (currarea->attr & ALTERNATE))) {
  94.         sprintf(filename," (%u:%u/%u): [S]ave, [A]bort, [C]arbons, [B]omb or [E]dit Header? [S] ",msg.d_zone,msg.dest_net,msg.dest);
  95.         any_message(filename);
  96.     }
  97.     else if(msg.d_zone==msg.o_zone && msg.dest==msg.orig && msg.dest_net==msg.orig_net && msg.d_point==msg.o_point && ((currarea->attr & NET) || (currarea->attr & ALTERNATE))) {
  98.         any_message(" (Misaddressed?) [S]ave, [A]bort, [C]arbons, [B]omb or [E]dit Header? [S] ");
  99.     }
  100.     else if((currarea->attr & NET) || (currarea->attr & ALTERNATE)) {
  101.         any_message("[S]ave, [A]bort, [C]arbons, [B]omb or [E]dit Header? [S] ");
  102.     }
  103.     else if(!(currarea->attr & ECHO) && !(currarea->attr & ALTECHO)) {
  104.         any_message(" [S]ave, [A]bort, [C]arbons or [E]dit Header? [S] ");
  105.     }
  106.     else any_message(" [S]ave, [A]bort, or [E]dit Header? [S] ");
  107.     temp=toupper(generic_mouse_input(ewnd));
  108.     switch ((int)temp) {
  109.         case CTRL_R: clear_message();
  110.                      goto EditSomeMore;
  111.         case ALT_O:  get_origin();
  112.                      goto AskAgain;
  113.         case CTRL_O: usedefault=1-usedefault;
  114.                      if(usedefault) any_message(" Always using default origin line");
  115.                      else any_message(" Looking up origin lines in ORIGINS.BBS ");
  116.                      pause();
  117.                      goto AskAgain;
  118.         case CTRL_W: wrapit=1-wrapit;
  119.                      if(wrapit || !wrapcall) _anymsg(" Toggled Wrapping "," OFF ");
  120.                      else _anymsg(" Toggled Wrapping "," ON ");
  121.                      pause();
  122.                      goto AskAgain;
  123.         case 13:
  124.         case 'S':    break;
  125.         case 'A':    level=1;
  126.                     get_rid();
  127.                     if(carbwnd)delete_window(carbwnd);
  128.                     if(numcarbons) {
  129.  
  130.                         int register x;
  131.  
  132.                         for(x=0;x<numcarbons;x++) if(carbon[x])free(carbon[x]);
  133.                     }
  134.                     if(bomb_addr)free(bomb_addr);
  135.                     return;
  136.         case 'E':   clear_message();
  137.                     edit_mess(2);
  138.                     goto AskAgain;
  139.         case 'C':   if((currarea->attr & ECHO) || (currarea->attr & ALTECHO)) goto AskAgain;
  140.                     if(numcarbons>18) {
  141.                         error_message(" Max # of carbons in use--Delete one ");
  142.                         nopause();
  143.                         goto AskAgain;
  144.                     }
  145.                     carbon[numcarbons]=(struct _carbon *)malloc(sizeof(struct _carbon));
  146.                     if(!carbon[numcarbons]) {
  147.                         error_message(" Insufficient memory for carbon ");
  148.                         pause();
  149.                         goto AskAgain;
  150.                     }
  151.                     if(!fill_in_carbon(carbon[numcarbons])) {
  152.                         free(carbon[numcarbons]);
  153.                     }
  154.                     else numcarbons++;
  155.                     goto AskAgain;
  156.         case 'D':    if(!numcarbons) goto AskAgain;
  157.                     else {
  158.  
  159.                         int x;
  160.                         int y;
  161.  
  162.                         any_message(" Select carbon.  [Enter] deletes, ESC aborts ");
  163.                         sleep(1);
  164.                         set_help("delcarbon ",0,23);
  165.                         clear_message();
  166.                         x=get_selection(carbwnd,numcarbons,NULL);
  167.                         if(x && x<numcarbons+1) {
  168.                             for(y=(x-1);y<numcarbons;y++) {
  169.                                 memcpy(carbon[y],carbon[y+1],sizeof(struct _carbon));
  170.                             }
  171.                             if(carbon[numcarbons-1])free(carbon[numcarbons-1]);
  172.                             numcarbons--;
  173.                         }
  174.                     }
  175.                     set_help ("atpost    ",0,23);
  176.                     goto AskAgain;
  177.         case 'B':    if((!(currarea->attr & NET) && !(currarea->attr & ALTERNATE)) || !nidxsize || numcarbons) goto AskAgain;
  178.                     bomb_addr=(struct _bomb_addr *)malloc(sizeof(struct _bomb_addr *));
  179.                     if(!bomb_addr) {
  180.                         error_message(" Insufficient memory for bomb run ");
  181.                         pause();
  182.                         goto AskAgain;
  183.                     }
  184.                     if(!bomb_who(bomb_addr)) {
  185.                         free(bomb_addr);
  186.                         bomb_addr=NULL;
  187.                         goto AskAgain;
  188.                     }
  189.                     break;
  190.         default:    goto AskAgain;
  191.     }
  192.  }
  193.  clear_message();
  194.  if(carbwnd) delete_window(carbwnd);
  195.  if (level) {
  196.     if (editor) {
  197.         any_message(" Aborted--Any Key ");
  198.         pause();
  199.     }
  200.     get_rid();
  201.     if(numcarbons) {
  202.  
  203.         int register x;
  204.  
  205.         for(x=0;x<numcarbons;x++) if(carbon[x])free(carbon[x]);
  206.     }
  207.     if(bomb_addr)free(bomb_addr);
  208.     return;
  209.  }
  210.  if (wrapcall && !wrapit && editor && !(currarea->attr & ANSI)) {
  211.     do_spawn(wrapcall);
  212.  }
  213.  sprintf(filename,"%sXDATA.%03x",path,areano);
  214.  sprintf(textname,"%sXTEXT.%03x",path,areano);
  215.  
  216. AccessLoop1:
  217.   if (findfirst(filename,&f,0)) flen=0;
  218.   else flen=f.ff_fsize;
  219.   if ((handlef=_open(filename,O_RDWR | O_BINARY | O_DENYNONE))==-1) {
  220.         if (errno==EACCES) {
  221.             any_message(" Awaiting access... ");
  222.             goto AccessLoop1;
  223.         }
  224.         if((handlef=creat(filename,S_IWRITE))==-1) {
  225.             error_message(" Can't open message base ");
  226.             pause();
  227.             get_rid();
  228.             if(numcarbons) {
  229.  
  230.                 int register x;
  231.  
  232.                 for(x=0;x<numcarbons;x++) if(carbon[x])free(carbon[x]);
  233.             }
  234.             if(bomb_addr)free(bomb_addr);
  235.             return;
  236.         }
  237.   }
  238.   clear_message();
  239.   lock(handlef,flen,(long)sizeof(struct _xmsg));
  240.   lseek(handlef,0L,SEEK_END);
  241.  
  242. AccessLoop:
  243.   if (findfirst(textname,&f,0))tlen=0;
  244.   else tlen=f.ff_fsize;
  245.   if ((handlet=_open(textname,O_RDWR | O_BINARY | O_DENYNONE))==-1) {
  246.     if (errno==EACCES) {
  247.         any_message(" Awaiting access... ");
  248.         goto AccessLoop;
  249.     }
  250.     if((handlet=creat(textname,S_IWRITE))==-1) {
  251.         error_message(" Can't open message files ");
  252.         _close(handlef);
  253.         pause();
  254.         get_rid();
  255.         if(numcarbons) {
  256.  
  257.             int register x;
  258.  
  259.             for(x=0;x<numcarbons;x++) if(carbon[x])free(carbon[x]);
  260.         }
  261.         if(bomb_addr)free(bomb_addr);
  262.         return;
  263.       }
  264.   }
  265.   clear_message();
  266.   lock(handlet,tlen,65535L);
  267.   lseek(handlet,0L,SEEK_END);
  268.  
  269.  lenmess=0;
  270.  
  271.  if (!*fname) {
  272.      strcpy(message,"MSGTMP");
  273.  }
  274.  else strcpy(message,fname);
  275.  
  276.  if (findfirst(message,&f,0)) mlen=0;
  277.  else mlen=f.ff_fsize;
  278.  if ((handlem=_open(message,O_RDONLY | O_BINARY | O_DENYNONE))==-1) {
  279.    error_message(" Read error...lost ");
  280.    _close(handlef);
  281.    _close(handlet);
  282.    pause();
  283.    if(numcarbons) {
  284.  
  285.       int register x;
  286.  
  287.        for(x=0;x<numcarbons;x++) if(carbon[x])free(carbon[x]);
  288.    }
  289.    if(bomb_addr)free(bomb_addr);
  290.    return;
  291.  }
  292.  lock(handlem,0,mlen);
  293.  msg.start=tell(handlet);
  294.  lenmess=0;
  295.  
  296.  if ((currarea->attr & NET) || (currarea->attr & ALTERNATE)) {
  297.  
  298.     c